package com.zhuiyun.educations.api.coursefile.mapper;

import com.zhuiyun.educations.api.coursefile.entity.CourseFile;
import com.zhuiyun.educations.api.coursefile.entity.UnitJoint;
import com.zhuiyun.educations.api.uploadFile.entity.FileManage;
import com.zhuiyun.educations.common.mapper.BaseMapper;
import com.zhuiyun.educations.util.pageUtil.PageRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface CourseFileMapper extends BaseMapper<CourseFile> {
    /**
     * @Author ys
     * @Description TODO 分页查询
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Select("SELECT * FROM course_file f LEFT JOIN unit_joint u ON f.joint_id = u.id LEFT JOIN course_unit cu ON cu.id = u.unit_id LEFT JOIN course_info ci ON ci.id = cu.course_id LEFT JOIN file_manage m ON f.file_id = m.id WHERE f.del_flag =0")
    List<CourseFile> getCourseFile(PageRequest pageRequest);
    /**
     * @Author ys
     * @Description TODO 课程动态下拉
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Select("SELECT * FROM course_file f LEFT JOIN course c ON f.course_id = c.id LEFT JOIN file_manage m ON f.file_id = m.id LEFT JOIN image_file i ON c.image_id = i.id where f.del_flag=0")

    List<CourseFile> selectAll();
    /**
     * @Author ys
     * @Description TODO 章节下拉
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Select("SELECT * FROM  unit_joint ")
    List<UnitJoint> fileSelect();
    /**
     * @Author ys
     * @Description TODO 逻辑删除
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Update("update course_file set del_flag=1 where id=#{id}")
    int deleteCourseFileById(int id);

    /**
    * @Author 杨友朋
    * @Description 添加文件信息
    * @Date 2023/6/27 14:54
    * @Return Integer
    * @param fileManage
    */
    @Insert("insert into file_manage (file_name,file_uuid_name,file_size,file_type,file_path,create_time) " +
            "values(#{fileName},#{fileUuidName},#{fileSize},#{fileSize},#{fileType},#{filePath},#{createTIme})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer insertFile(FileManage fileManage);

    /**
    * @Author 杨友朋
    * @Description 根据id单查
    * @Date 2023/6/27 15:01
    * @Return FileManage
    * @param id
    */
    @Select("select * from file_manage where id=#{id}")
    FileManage selectOneById(Integer id);
}
